`timescale 1ns / 1ps
//////////////////////////////////////////////////////////////////////////////////
// Company: 
// Engineer: 
// 
// Create Date:    23:43:47 02/28/2014 
// Design Name: 
// Module Name:    vga_display 
// Project Name: 
// Target Devices: 
// Tool versions: 
// Description: 
//
// Dependencies: 
//
// Revision: 
// Revision 0.01 - File Created
// Additional Comments: 
//
//////////////////////////////////////////////////////////////////////////////////
module vga_display(	splash_screen,splash_color,splash_border,
							backdrop, bg_tile,
							character, w_sprite,
							projectile,bullet_sprite,
							pheonix,pheonix_sprite,
							sprite1,sprite2,sprite3,sprite4,sprite5,sprite6,sprite7,sprite8,sprite_color,							
							HP_Bar_pheonix,HP_Bar_inverse,HP_Bar_Border,
							score_bar,score_border,
							
							rst,clk, 
							blank,
							R, G, B, 
							HS,VS,
							hcount,vcount);
	//////////////////////////////////////////////////////////////////////////////////
	input clk,rst;
	input [7:0] splash_color;
	input [7:0] bg_tile;
	input [7:0] w_sprite;
	input [7:0] bullet_sprite;
	input [7:0] pheonix_sprite;
	input [7:0] sprite_color;
	
	input	splash_screen;
	input	splash_border;
	input	backdrop;
	input character;
	input projectile;
	input pheonix;
	input sprite1;
	input sprite2;
	input sprite3;
	input sprite4;
	input sprite5;
	input sprite6;
	input sprite7;
	input sprite8;
	input HP_Bar_pheonix,
			HP_Bar_inverse,
			HP_Bar_Border,
			score_bar,
			score_border;
	
	//////////////////////////////////////////////////////////////////////////////////
	output reg [2:0] R, G;
	output reg [1:0] B;
	output HS;
	output VS;
	output blank;
	output[10:0] hcount,vcount;
	//////////////////////////////////////////////////////////////////////////////////
	wire [10:0] hcount, vcount;    // coordinates for the current pixel
	wire blank;   						 // signal to indicate the current coordinate is blank
	wire an_enemy;
	assign an_enemy_sprite = sprite1 | sprite2 | sprite3 | sprite4 | sprite5 | sprite6 | sprite7 | sprite8;

   // Call driver
    vga_controller_640_60 vc(
			.rst(rst),
        .pixel_clk(clk), 
        .HS(HS), 
        .VS(VS), 
        .hcounter(hcount), 
        .vcounter(vcount), 
        .blank(blank));

   // --------- MAIN DRAWING BLOCK ------------------------------------
	
	always @ (posedge clk) begin
		if(rst) begin
			{R,G,B} <= 0;
		end
		// --------- SPLASH SCREEN --------------------------------
		if (splash_screen) begin
			if (splash_color != 8'hFF) begin
				{R,G,B} <= splash_color;
			end else begin
				{R,G,B} <= 8'b10100011;
			end
	
		end
		else if (splash_border) begin
			{R,G,B} <= 8'b10100011;
		end
		// --------- MAIN CHARACTER -------------------------------
		else if (character) begin
			if (w_sprite != 8'hFF) begin
				{R,G,B} <= w_sprite;
			end else if( an_enemy_sprite && sprite_color!= 8'hFF) begin
				{R,G,B} <= sprite_color;
			end else if(pheonix && pheonix_sprite!= 8'hFF) begin
				{R,G,B} <= pheonix_sprite;
			end else begin
				{R,G,B} <= bg_tile;
			end
	
		end
		// --------- HP BARs FOR PHEONIX BOSS ---------------------	
		else if (HP_Bar_pheonix) begin
			{R,G,B} <= 8'b11100000;
		end
		else if (HP_Bar_inverse) begin
			{R,G,B} <= 8'b00000000;
		end
		else if (HP_Bar_Border) begin
			{R,G,B} <= 8'b11111111;
		end
		else if (score_bar) begin
			{R,G,B} <= 8'b00110001;
		end
		else if (score_border) begin
			{R,G,B} <= 8'b11111111;
		end
		// --------- BULLET ---------------------------------------		
		else if (projectile) begin
			if ( !backdrop) begin
				{R,G,B} <=0;
			end
			else if (bullet_sprite != 8'hFF) begin
				{R,G,B} <= bullet_sprite;
			end else if(an_enemy_sprite && sprite_color != 8'hFF) begin
				{R,G,B} <= sprite_color;
			end else if(pheonix && pheonix_sprite != 8'hFF) begin
				{R,G,B} <= pheonix_sprite;
			end else begin
				{R,G,B} <= bg_tile;
			end
		end
		
		
		// ----- SPRITE FOR THE BOSS --------------------
		else if (pheonix) begin
			if ( !backdrop ) begin
				{R,G,B} <= 0;
			end else if (pheonix_sprite != 8'hFF) begin
				{R,G,B} <= pheonix_sprite;
			end else if (an_enemy_sprite && sprite_color != 8'hFF) begin
				{R,G,B} <= sprite_color;
			end else begin
				{R,G,B} <= bg_tile;
			end	
		end
		
		// --------- ENEMY SPRITES --------------------------------
		else if (sprite1) begin
			if ( !backdrop ) begin
				{R,G,B} <= 0;
			end else if (sprite_color != 8'hFF) begin
				{R,G,B} <= sprite_color;
			end else begin
				{R,G,B} <= bg_tile;
			end
		end
		else if (sprite2) begin
			if ( !backdrop ) begin
				{R,G,B} <= 0;
			end else if (sprite_color != 8'hFF) begin
				{R,G,B} <= sprite_color;
			end else begin
				{R,G,B} <= bg_tile;
			end
		end
		else if (sprite3) begin
			if ( !backdrop ) begin
				{R,G,B} <= 0;
			end else if (sprite_color != 8'hFF) begin
				{R,G,B} <= sprite_color;
			end else begin
				{R,G,B} <= bg_tile;
			end
		end
		else if (sprite4) begin
			if ( !backdrop ) begin
				{R,G,B} <= 0;
			end else if (sprite_color != 8'hFF) begin
				{R,G,B} <= sprite_color;
			end else begin
				{R,G,B} <= bg_tile;
			end
		end
		else if (sprite5) begin
			if ( !backdrop ) begin
				{R,G,B} <= 0;
			end else if (sprite_color != 8'hFF) begin
				{R,G,B} <= sprite_color;
			end else begin
				{R,G,B} <= bg_tile;
			end
		end
		else if (sprite6) begin
			if ( !backdrop ) begin
				{R,G,B} <= 0;
			end else if (sprite_color != 8'hFF) begin
				{R,G,B} <= sprite_color;
			end else begin
				{R,G,B} <= bg_tile;
			end
		end
		else if (sprite7) begin
			if ( !backdrop ) begin
				{R,G,B} <= 0;
			end else if (sprite_color != 8'hFF) begin
				{R,G,B} <= sprite_color;
			end else begin
				{R,G,B} <= bg_tile;
			end
		end
		else if (sprite8) begin
			if ( !backdrop ) begin
				{R,G,B} <= 0;
			end else if (sprite_color != 8'hFF) begin
				{R,G,B} <= sprite_color;
			end else begin
				{R,G,B} <= bg_tile;
			end
		end
		
		
		// --- BACKGROUND AND BLACK --------------------------------
		
		else if (backdrop) begin
			{R,G,B} <= bg_tile;
		end
					
		else begin    // if you are outside the valid region
			{R,G,B} <= 0;
		end
	end

endmodule
